import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    ipAndPort: window.localStorage.ipAndPort || '',
    index: 0,
    // uri: 'http://192.168.3.33:8101/carsize',
    loading: false,
    search: {
      jyxm: ''
    },
    checkConn: false,
    title: '主页',
    carInfo: {
      jyxm: '',
      hphm: '',
      jylsh: '',
      jyjgbh: '',
      jcxdh: window.localStorage.jcxdh || 1,
      kssj: '',
      sjsj: ''
    },
    history: [
      '/'
    ]
  },
  getters: {
    uri: (state, getters) => {
      return `http://${state.ipAndPort}/carsize`
    }
  },
  mutations: {
    setIpAndPort(state, value) {
      state.ipAndPort = value;
    },
    setIndex(state, value) {
      state.index = value;
    },
    setTitle(state, value) {
      state.title = value;
    },
    setCarInfo(state, value) {
      for (const key in value) {
        state.carInfo[key] = value[key];
      }
    },
    setHistory(state, value) {
      state.history = value;
    },
    setLoading(state, value) {
      state.loading = value;
    },
    setSearch(state, value) {
      for (const key in value) {
        state.search[key] = value[key];
      }
    },
    setCheckConn(state, value) {
      state.checkConn = value;
    }
  },
  actions: {},
  modules: {}
})
